﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication2.Models;
using System.Data;

namespace MvcApplication2.Delegale.Concrete
{
    public class ProductDelegate : Interface.IProductDelegate
    {
          private ProductDbcontext context;

        public ProductDelegate(ProductDbcontext context)
        {
            this.context = context;
        }
        public IEnumerable<Product> GetProducts()
        {
            return context.Products.ToList();
        }

        public Product GetProductByID(int id)
        {
            return context.Products.SingleOrDefault(p => p.Id == id);
        }

        public void InsertProduct(Product Product)
        {
            context.Products.Add(Product);
        }

        public void DeleteProduct(int ProductID)
        {
            Product Product = context.Products.Find(ProductID);
            context.Products.Remove(Product);
        }

        public void UpdateProduct(Product Product)
        {
            context.Entry(Product).State = EntityState.Modified;
        }

        public void Save()
        {
            context.SaveChanges();
        }
    }
}